#include "gtest/gtest.h"
#include "../BaseUtil/MyTest.h"
#include "DOMCoreImp.h"
namespace DOMCoreImp {

class AttrImpTest : public testing::Test {
protected:
	class DummyAttrImp : public AttrImp {
	public:
		DummyAttrImp(DOMString nodeName, DocumentImp * ownerDocument)
		: AttrImp( nodeName, ownerDocument ) {}
	};

	virtual void SetUp() {
		attr = new DummyAttrImp("DUMMY_ATTR", NULL);
	}
	virtual void TearDown() {
		delete attr;
	}

	AttrImp * attr;
};

TEST_F(AttrImpTest, Inheritance) {
	Attr * attrBase = (Attr*) attr;
	Node * nodeBase = (Node*) attr;
	NodeImp * nodeImp = (NodeImp*) attr;
	attrBase = NULL;
	nodeBase = NULL;
	nodeImp = NULL;
}

TEST_F(AttrImpTest, NodeType) {
	ASSERT_EQ( Node::ATTRIBUTE_NODE, attr->getNodeType() );
}

TEST_F(AttrImpTest, Name) {
	ASSERT_STREQ( "DUMMY_ATTR", attr->getName().c_str() );
}

TEST_F(AttrImpTest, Value) {
	const char * const values[] = { "Jay", "RongRong", "Ross", "Helen" };

	attr->setValue(values[0]);
	ASSERT_STREQ( values[0], attr->getValue().c_str() );

	attr->setValue(values[1]);
	ASSERT_STREQ( values[1], attr->getValue().c_str() );

	attr->setValue(values[2]);
	ASSERT_STREQ( values[2], attr->getValue().c_str() );

	attr->setValue(values[3]);
	ASSERT_STREQ( values[3], attr->getValue().c_str() );
}

TEST_F(AttrImpTest, Attribute) {
	ASSERT_FALSE( attr->hasAttributes() );
	ASSERT_FALSE( attr->getAttributes() );
}

TEST_F(AttrImpTest, Child) {
	ASSERT_THROW( attr->insertBefore( NULL, NULL ), DOMExceptionPtr );
	ASSERT_THROW( attr->replaceChild( NULL, NULL ), DOMExceptionPtr );
	ASSERT_THROW( attr->removeChild( NULL ), DOMExceptionPtr );
	ASSERT_THROW( attr->appendChild( NULL ), DOMExceptionPtr );
}

}
